import axios from '../../utils/http'

const model = {
    namespaced: true, //形成对立的命名空间
    state(){
        //数据
        return {
            goodsList: [],
            count: 0
        }    
    },
    mutations: {
        goodsCountMutation(state,count){
            //设置数据
            state.count = count
        },
        goodsListMutation(state,list){
            //设置数据
            state.goodsList = list
        }
    },
    actions: {
        goodsCountActions(context){
            //请求数据
            axios.get("/goodscount").then(res=>{
                context.commit("goodsCountMutation",res.list[0].total)
            })
        },
        goodsListActions(context,obj){
            //请求数据
            //obj = {page: 1,size: 2}
            axios.get("/goodslist",{params:obj}).then(res=>{
                context.commit("goodsListMutation",res.list)
            })
        }
    }
}

export default model